<template>
  <div>
    <table class="table table-border" border=1>
       <h2 algin="center">借款信息修改页面</h2>
       <tr>
        <td>借款款项名称</td>
        <td>
          <input type="text" v-model="state.Bname">
        </td>
       </tr>
       <tr>
        <td>借款最高金额</td>
        <td>
          <input type="text" v-model="state.MaxMoney">
        </td>
       </tr>
       <tr>
        <td>借款最高年限</td>
        <td>
          <input type="text" v-model="state.MaxYear">
        </td>
       </tr>
       <tr>
        <td>利息编号</td>
        <td>
          <select v-model="state.Lid">
            <option v-for="item in list" :value="item.Lid" >每年{{item.Lnum}}%</option>
          </select>
        </td>
       </tr>
       <tr>
        <td>借款款项简介</td>
        <td>
          <textarea v-model="state.Bremark"></textarea>
        </td>
       </tr>
       <tr>
        <td colspan="2"><input type="button" value="修改" @click="add"></td>
       </tr>
    </table>
   
  </div>
</template>

<script setup lang="ts">
  import router from '@/router';
import axios from 'axios';
import {reactive,toRefs,onMounted} from 'vue'
  onMounted(()=>{
    GetList();
  })
  let data=reactive({
    state:{
      Bname:"",
      MaxMoney:"",
      MaxYear:"",
      Lid:0,
      Bremark:""
    },
    list:[]
  })
  
  let{state,list}=toRefs(data);
  function GetList()
  {
    axios({
      url:"http://localhost:61513/api/borrow/GetLxInfoList",
      method:"get",
    })
    .then(res=>{
      console.log(res);
      list.value=res.data.data
    })
    .catch(err=>{
      console.log(err);
    })
  }
  function add()
  {
    if(state.value.Bname=="")
    {
      alert("借款款项名称不能为空");
      return
    }
    if(state.value.MaxMoney=="")
    {
      alert("最高金额不能为空");
      return
    }
    if(Number(state.value.MaxMoney)<=0 || isNaN(Number(state.value.MaxMoney))==true)
    {
      alert("最高借款金额为数字且必须大于0")
      return;
    }
    if(state.value.MaxYear=="")
    {
      alert("借款最高年限不能为空");
      return
    }
    if(state.value.Bremark=="")
    {
      alert("备注不能为空");
      return
    }
   alert("修改成功");
   router.push("/borrowlist");
    
  }
</script>

<style scoped>

</style>